<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Material of Analysis | 部署</title>
    <meta name="description" content="The analytical data that you often use to learn">
    <link rel="icon" href="/material/logo.png">
  <link rel="manifest" href="/material/manifest.json">
  <meta name="theme-color" content="#3eaf7c">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/material/icons/apple-touch-icon-152x152.png">
  <link rel="mask-icon" href="/material/icons/safari-pinned-tab.svg" color="#3eaf7c">
  <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
  <meta name="msapplication-TileColor" content="#000000">
    
    <link rel="preload" href="/material/assets/css/0.styles.89749010.css" as="style"><link rel="preload" href="/material/assets/js/app.671f232e.js" as="script"><link rel="preload" href="/material/assets/js/5.3a34f633.js" as="script"><link rel="prefetch" href="/material/assets/js/9.6ad28882.js"><link rel="prefetch" href="/material/assets/js/1.a893eea4.js"><link rel="prefetch" href="/material/assets/js/2.ad32dd32.js"><link rel="prefetch" href="/material/assets/js/3.2af42d2c.js"><link rel="prefetch" href="/material/assets/js/4.b8a50edf.js"><link rel="prefetch" href="/material/assets/js/6.36baf8b1.js"><link rel="prefetch" href="/material/assets/js/7.23741c7b.js"><link rel="prefetch" href="/material/assets/js/8.0b506f6a.js"><link rel="prefetch" href="/material/assets/js/10.aa5bc1f8.js"><link rel="prefetch" href="/material/assets/js/11.b5d01b0b.js"><link rel="prefetch" href="/material/assets/js/12.2aab57fe.js"><link rel="prefetch" href="/material/assets/js/13.17c8fcb3.js"><link rel="prefetch" href="/material/assets/js/14.b0d8de38.js"><link rel="prefetch" href="/material/assets/js/15.95c4b4d8.js"><link rel="prefetch" href="/material/assets/js/16.8279b098.js"><link rel="prefetch" href="/material/assets/js/17.c88c3a9c.js"><link rel="prefetch" href="/material/assets/js/18.0635186f.js"><link rel="prefetch" href="/material/assets/js/19.5e722a99.js">
    <link rel="stylesheet" href="/material/assets/css/0.styles.89749010.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div><a href="/material/" class="home-link router-link-active"><!----><span class="site-name">
      Material of Analysis
    </span></a><div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""><!----></div><nav class="nav-links can-hide"><div class="nav-item"><a href="/material/basic/" class="nav-link">基础</a></div><a href="https://github.com/docschina/vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header><div class="sidebar-mask"></div><div class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/material/basic/" class="nav-link">基础</a></div><a href="https://github.com/docschina/vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav><!----></div><div class="page"><div class="content"><h1 id="部署"><a href="#部署" aria-hidden="true" class="header-anchor">#</a> 部署</h1><p>以下指南基于几个共同的假设：</p><ul><li>将文档放置在项目的 <code>docs</code> 目录中；</li><li>使用默认的构建输出位置（<code>.vuepress/dist</code>）。</li><li>VuePress 是在项目本地的依赖中安装的，并且配置如下的 npm scripts:</li></ul><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;scripts&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;docs:build&quot;</span><span class="token operator">:</span> <span class="token string">&quot;vuepress build docs&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><h2 id="github-页面"><a href="#github-页面" aria-hidden="true" class="header-anchor">#</a> GitHub 页面</h2><ol><li><p>在 <code>docs/.vuepress/config.js</code> 中设置正确的 <code>base</code>。</p><p>如果你想要部署到 <code>https://&lt;USERNAME&gt;.github.io/</code>，则可以省略设置 <code>base</code>，因为它默认是 &quot;/&quot;。</p><p>如果你想要部署到 <code>https://&lt;USERNAME&gt;.github.io/&lt;REPO&gt;/</code>（，也就是说你的仓库位于 <code>https://github.com/&lt;USERNAME&gt;/REPO&gt;</code>），将 <code>base</code> 设置为 <code>&quot;/&lt;REPO&gt;/&quot;</code>。</p></li><li><p>在项目中创建 <code>deploy.sh</code>，并写入如下内容（根据自己项目的情况，取消高亮行的注释），然后在部署时执行此 shell 脚本：</p></li></ol><pre class="language-bash"><code><span class="token comment">#!/usr/bin/env sh</span>

<span class="token comment"># 确保脚本抛出遇到的错误</span>
<span class="token keyword">set</span> -e

<span class="token comment"># 构建</span>
<span class="token function">npm</span> run docs:build

<span class="token comment"># 进入到构建输出目录</span>
<span class="token function">cd</span> docs/.vuepress/dist

<span class="token comment"># 如果你是要部署到自定义域名</span>
<span class="highlighted-line"><span class="token comment"># echo 'www.example.com' &gt; CNAME</span></span>
<span class="token function">git</span> init
<span class="token function">git</span> add -A
<span class="token function">git</span> commit -m <span class="token string">'deploy'</span>

<span class="token comment"># 如果你想要部署到 https://&lt;USERNAME&gt;.github.io</span>
<span class="highlighted-line"><span class="token comment"># git push -f git@github.com:&lt;USERNAME&gt;/&lt;USERNAME&gt;.github.io.git master</span></span>
<span class="token comment"># 如果你想要部署到 https://&lt;USERNAME&gt;.github.io/&lt;REPO&gt;</span>
<span class="highlighted-line"><span class="token comment"># git push -f git@github.com:&lt;USERNAME&gt;/&lt;REPO&gt;.git master:gh-pages</span></span>
<span class="token function">cd</span> -
</code></pre><div class="tip custom-block"><p class="custom-block-title">提示</p><p>还可以通过 CI 配置，执行以上脚本，以启用在每次推送时的自动部署。</p></div><h2 id="gitlab-pages-和-gitlab-ci"><a href="#gitlab-pages-和-gitlab-ci" aria-hidden="true" class="header-anchor">#</a> GitLab pages 和 GitLab CI</h2><ol><li><p>在 <code>docs/.vuepress/config.js</code> 中设置正确的 <code>base</code>。</p><p>如果你想要部署到 <code>https://&lt;USERNAME or GROUP&gt;.gitlab.io/</code>，则可以省略设置 <code>base</code>，因为它默认是 &quot;/&quot;。</p><p>如果你想要部署到 <code>https://&lt;USERNAME or GROUP&gt;.gitlab.io/&lt;REPO&gt;/</code>（，也就是说你的仓库位于 <code>https://gitlab.com/&lt;USERNAME&gt;/REPO&gt;</code>），将 <code>base</code> 设置为 <code>&quot;/&lt;REPO&gt;/&quot;</code>。</p></li><li><p>将 <code>.vuepress/config.js</code> 中的 <code>dest</code> 设置为 <code>public</code>。</p></li><li><p>在项目的根目录下，创建一个 <code>.gitlab-ci.yml</code> 文件，并写入如下内容。在内容变更之后，GitLab CI 会立刻去构建和部署你的网站。</p></li></ol><pre class="language-text"><code>image: node:9.11.1

pages:
  cache:
    paths:
    - node_modules/

  script:
  - npm install
  - npm run docs:build
  artifacts:
    paths:
    - public
  only:
  - master
</code></pre><h2 id="netlify"><a href="#netlify" aria-hidden="true" class="header-anchor">#</a> Netlify</h2><ol><li>在 Netlify 中, 从 GitHub 创建一个新项目，使用以下设置：</li></ol><ul><li><strong>构建命令：</strong><code>npm run docs:build</code> or <code>yarn docs:build</code></li><li><strong>发布目录：</strong><code>docs/.vuepress/dist</code></li></ul><ol start="2"><li>点击部署按钮！</li></ol><h2 id="google-firebase"><a href="#google-firebase" aria-hidden="true" class="header-anchor">#</a> Google Firebase</h2><ol><li><p>请确保你已经安装了 <a href="https://www.npmjs.com/package/firebase-tools" target="_blank" rel="noopener noreferrer">firebase-tools</a>。</p></li><li><p>在项目的根目录下，创建 <code>firebase.json</code> 和 <code>.firebaserc</code> 文件，并写入如下内容：</p><p><code>firebase.json</code>:</p><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;hosting&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;public&quot;</span><span class="token operator">:</span> <span class="token string">&quot;./docs/.vuepress/dist&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;ignore&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p><code>.firebaserc</code>:</p><pre class="language-js"><code><span class="token punctuation">{</span>
  <span class="token string">&quot;projects&quot;</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token string">&quot;default&quot;</span><span class="token punctuation">:</span> <span class="token string">&quot;&lt;YOUR_FIREBASE_ID&gt;&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></li><li><p>在执行  <code>yarn docs:build</code>  或 <code>npm run docs:build</code> 之后, 使用 <code>firebase deploy</code> 指令进行部署。</p></li></ol><hr><blockquote><p>原文：<a href="https://vuepress.vuejs.org/guide/deploy.html" target="_blank" rel="noopener noreferrer">https://vuepress.vuejs.org/guide/deploy.html</a></p></blockquote><hr></div><div class="content edit-link"><a href="https://github.com/docschina/vuepress/edit/master/docs/guide/deploy.md" target="_blank" rel="noopener noreferrer">在GitHub上编辑此页</a><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div><!----></div></div></div>
    <script src="/material/assets/js/5.3a34f633.js" defer></script><script src="/material/assets/js/app.671f232e.js" defer></script>
  </body>
</html>
